
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    avatar_image: "",
    text: "",
    nickname: "",
    list: [],
    language: "",

    isLoadMore: true,
    page: 1,
    total_page: 0,

    un_settlement_count: 0,
    finish_settlement_count: 0,
    one_consignment_sum: 0,
    consignment_sum: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    let language = wx.getStorageSync('langIndex');
    this.setData({
      'language': language.en,
    })
    this.getData();
    this.get_total()
  },

  get_total() {
    app._postNetWork({
      url:app.getNetAddresss('plugin.consignment.frontend.controllers.withdrawal.index'),
      success:resdata=>{
        let {result,msg} = resdata.data;
        if(result){
          let {member,plugin_name,statistics} = resdata.data.data;
          this.setData({
            un_settlement_count:statistics.un_settlement_count,
            finish_settlement_count:statistics.finish_settlement_count,
            one_consignment_sum:statistics.one_consignment_sum,
            consignment_sum:statistics.consignment_sum,
            username:member.username,
            avatar_image:member.avatar_image
          })
          wx.setNavigationBarTitle({
            title: plugin_name,
          })
        }else{
          app.tips(msg)
        }
      }
    })
   
  },
  change(e) {
    this.setData({active:e.detail.index})
    this.getData(1)
  },
  getData(page = 1) {
    let json = {
      page,
      status:this.data.active - 1
    }
    if(this.data.active == 0 ){
      delete json.status
    }
    app._postNetWork({
      url:app.getNetAddresss('plugin.consignment.frontend.controllers.withdrawal.get-exchange-voucher-list'),
      data:json,
      success:resdata=>{
        let { result ,msg} = resdata.data;
        if(result){
          let {settlement_record_list} = resdata.data.data;
          let _list = [];
          (page == 1) ? (_list = settlement_record_list.data ||  []) : (_list = this.list.concat([settlement_record_list.data]));
          this.data.page = settlement_record_list.current_page;
          this.data.total_page = settlement_record_list.last_page;
          this.setData({
            list:_list
          })
        }else{
          app.tips(msg)
        }
      }
    })
   
  },
  getMoreData() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    this.getData(page)
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData()
  }, 

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})